package com.qyl.main;

import com.qyl.mainclass.Animal;
import com.qyl.homework.Dog;
import com.qyl.homeworkone.ChinaDog;

public class MainOne {
    public static void main(String[] args){
        //实例化Animal类的对象
        Animal animal = new Animal( "黑二" , 3 , "黑色" , "犬类");
        animal.eat();
        animal.drink();
        animal.drink();

        //实例化Dog类的对象数组
        Dog[] dog = new Dog[3];

        //定义一个新的数组用来存放删除后的实例对象属性
        Dog[] dogOne = new Dog[dog.length - 1];

        //增
        dog[0] = new Dog("金毛" , 3 , "黄色" , "犬类");
        dog[1] = new Dog("哈士奇" ,  2 , "黑色" , "犬类");
        dog[2] = new Dog("藏獒" ,  4 , "黑白" , "犬类");
        System.out.println("\n");

        //查
        for (Dog dogOn : dog){
            System.out.println( "名字是："+ dogOn.getName() + "\t" + "年龄是：" + dogOn.getAge() + "\t" + "颜色是:" + dogOn.getColor() + "\t" + "种类是："+ dogOn.getType());
        }
        System.out.println("\n");

        //改
        for (int i = 0; i < dog.length  ; i++) {
            if( "哈士奇".equals(dog[i].getName())) {
                dog[i].setName("阿拉斯加");
            }
        }

        //查看是否修改成功
        for (Dog dogOn : dog){
            System.out.println( "名字是："+ dogOn.getName() + "\t" + "年龄是：" + dogOn.getAge() + "\t" + "颜色是:" + dogOn.getColor() + "\t" + "种类是："+ dogOn.getType());
        }
        System.out.println("\n");



        //删
        int count = 0;
        for (int i = 0; i < dog.length; i++) {
            if(!"阿拉斯加".equals(dog[i].getName())){
                dogOne[count++] = dog[i];
            }
        }

        //查看是否删除成功
        for (Dog dogOn : dogOne){
            System.out.println( "名字是："+ dogOn.getName() + "\t" + "年龄是：" + dogOn.getAge() + "\t" + "颜色是:" + dogOn.getColor() + "\t" + "种类是："+ dogOn.getType());
        }
        System.out.println("\n");


        //实例化ChinaDog对象
        ChinaDog chinaDog = new ChinaDog("黑二" , 3 , "黑色" , "犬类");
        chinaDog.eat();
        chinaDog.drink();
        chinaDog.sleep();
        chinaDog.sound();
        chinaDog.function();
    }
}
